<template>
    <h2>当前求和为：{{ count }}+{{ doubleCount }}</h2>
    <button @click="addSum">+</button>
    {{ car }}___{{ toy }}
    <propsTest :car = "car" @get-Toy = "getToy"></propsTest>
  </template>
  
  <script setup lang="ts" name="Count">
    // 引入对应的useXxxxxStore	
    import {ref} from 'vue'
    import {useCountStore} from '@/store/count'
    import {storeToRefs} from 'pinia'
    import propsTest from  '@/components/propsTest.vue'
    import emitter from '@/utils/emitter'
    import { onUnmounted } from 'vue'
    // 调用useXxxxxStore得到对应的store
    const sumStore = useCountStore()
    console.log(sumStore,'addCount');
    const {count,doubleCount} = storeToRefs(sumStore)
    console.log(count,doubleCount,'count');
    function addSum(){
        sumStore.addCount(2)
    }
    const car = ref('11111')
    const toy = ref('笔记本')
    function getToy(val:string) {
        toy.value = val
    }
    emitter.on('get-Toy-emitter',(val:string)=>{
        toy.value = val
    })
    onUnmounted(()=>{
        emitter.off('get-Toy-emitter')
    })
  </script>